package utils

import (
	"golang.org/x/text/cases"
	"golang.org/x/text/language"
	"regexp"
	"strconv"
	"strings"
	"unicode"
)

// Str2UintArr 字符串转uint数组, 默认逗号分割
func Str2UintArr(str string) (ids []uint) {
	idArr := strings.Split(str, ",")
	for _, v := range idArr {
		ids = append(ids, Str2Uint(v))
	}
	return
}

// Str2Uint 字符串转uint
func Str2Uint(str string) uint {
	num, err := strconv.ParseUint(str, 10, 32)
	if err != nil {
		return 0
	}
	return uint(num)
}

// ToUpperCamelCase 转为大驼峰命名
func ToUpperCamelCase(s string) string {
	var re = regexp.MustCompile("(_|-)([a-zA-Z]+)")
	camel := re.ReplaceAllString(s, " $2")
	// 用于将所有单词首字母转为大写字母
	c := cases.Title(language.English)
	camel = strings.Replace(c.String(camel), " ", "", -1)
	return camel
}

// ToLowerCamelCase 小驼峰命名
func ToLowerCamelCase(s string) string {
	camel := ToUpperCamelCase(s)
	if len(camel) == 0 {
		return camel
	}
	return string(unicode.ToLower(rune(camel[0]))) + camel[1:]
}
